import { Provide} from '@midwayjs/core';
import { Idle } from '../../entity/user/idle';
import { InjectEntityModel } from '@midwayjs/orm';
import { Repository } from 'typeorm';


@Provide()
export class IdleService {

  @InjectEntityModel(Idle)
  idleModel:Repository<Idle>

  async getidle(ownerid: string):Promise<Idle[]>{
    try{
      const result = await this.idleModel.find({
        where: {
          ownerid:ownerid
        }
    })
      console.log("result",result);
      return result
    }catch(err){
      console.log("err",err);
      
    }
  }
  
  async idle(idle:Idle):Promise<Idle>{
    try{
      const result = await this.idleModel.save(idle);
      console.log("result",result);
      return result
    }catch(err){
      console.log("err",err);
      
    }
  }

  async addidlepic(data,id):Promise<Idle>{
    try{
      const res = await this.idleModel.findOneBy({id})
      res.image = data
      const result = await this.idleModel.save(res);
      return result
    }catch(err){
      console.log("err",err);
      
    }
  }

  
}
